define(['../models/BaseModel', 'jquery'], function(BaseModel, $){
    var $ = require('jquery');
    var extend = {
        Toast: function(content, time, callback){
            var toastDom = [
                '<div class="toastWrap">',
                    '<span class="toastTitle">' + content + '</span>',
                '</div>'
            ].join(''), $toastDom = $(toastDom);

            $('body').append($toastDom);

            if(!time){
                time = 1000;
            }
            setTimeout(function(){
                $toastDom.remove();
                (callback && typeof(callback) === "function") && callback();
            }, time );
        },
        sendGetData: function(url, data, callback, errorcallback) {
            var baseModel = new BaseModel();
            var options = {
                type: "GET",
                url: url,
                data: data,
                datatype: "json", //"xml", "html", "script", "json", "jsonp", "text".
                success: callback,
                error: errorcallback
            }
            baseModel.loadData(options);
        },
        sendData: function(url, data, callback, errorcallback) {
            var baseModel = new BaseModel();
            var options = {
                type: "POST",
                url: url,
                data: data,
                datatype: "json", //"xml", "html", "script", "json", "jsonp", "text".
                success: callback,
                error: errorcallback
            }
            baseModel.loadData(options);
        },
        getData: function(url, callback, errorcallback) {
            var baseModel = new BaseModel();
            var options = {
                type: "GET",
                url: url,
                datatype: "json", //"xml", "html", "script", "json", "jsonp", "text".
                success: callback,
                error: errorcallback
            }
            baseModel.loadData(options);
        },
        setCookie: function(c_name,value,expiredays){
            var exdate=new Date();
            exdate.setDate(exdate.getDate()+expiredays);
            document.cookie = c_name + "=" + escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
        },
        getCookie: function (c_name){
            if (document.cookie.length>0){
                c_start=document.cookie.indexOf(c_name + "=");
                if (c_start != -1){
                    c_start = c_start + c_name.length + 1;
                    c_end = document.cookie.indexOf(";",c_start);
                    if (c_end == -1){
                        c_end = document.cookie.length;
                    }
                    return unescape(document.cookie.substring(c_start,c_end));
                }
            }
            return false;
        },
        getlocalStorage: function(name){
            var data = localStorage.getItem(name);
            if(data){
                return JSON.parse(data);
            }else{
                return false;
            }

        },
        setlocalStorage: function(name,data){
            return localStorage.setItem(name,JSON.stringify(data));
        },
        getSessionStorage: function(name){
            var data = sessionStorage.getItem(name);
            if(data){
                return JSON.parse(data);
            }else{
                return false;
            }

        },
        setSessionStorage: function(name,data){
            return sessionStorage.setItem(name,JSON.stringify(data));
        },

        findComponentInAll:function(components,componetid){
            var result;
            for(var i=0;i<components.length;i++){
                if(components[i].id==componetid){
                    return components[i];
                }else if(components[i].components){
                    result=this.findComponentInAll(components[i].components,componetid);
                    if(result){
                        break;
                    }
                }
            }
            return result;
        }
    };
    return extend;
});
